'use strict';

/**
 * @param {Egg.Application} app - egg application
 */
module.exports = app => {
  const { router, controller, middleware } = app;
  const { sign, auth, rbac } = middleware;

  // 是否开启API签名验证
  const enableRSAChecker = false;

  // 注意中间件的执行顺序
  const checks = enableRSAChecker ? [sign(), auth(), rbac()] : [auth()];

  // 上传
  router.post('/api/upload/file', controller.upload.file);

  // 登录
  if (enableRSAChecker) {
    router.post('/api/user/login', sign(), controller.user.login);
  } else {
    router.post('/api/user/login', controller.user.login);
  }
  // 会员
  router.get('/api/user/list', controller.user.allList);
  router.resources('user', '/api/user', controller.user);
  // role
  router.get('/api/role/list', controller.role.allList);
  router.resources('role', '/api/role', controller.role);

  // banner
  router.get('/api/banner/list', controller.banner.allList);
  router.resources('banner', '/api/banner', controller.banner);

  // notice
  router.get('/api/notice/list', controller.notice.allList);
  router.resources('notice', '/api/notice', controller.notice);

  // news
  router.get('/api/news/list', controller.news.allList);
  router.resources('news', '/api/news', controller.news);
  // post
  router.get('/api/post/list', controller.post.allList);
  router.resources('post', '/api/post', controller.post);
  // comment
  router.get('/api/comment/list', controller.comment.allList);
  router.resources('comment', '/api/comment', controller.comment);
  // collect
  router.get('/api/collect/list', controller.collect.allList);
  router.resources('collect', '/api/collect', controller.collect);
  // like
  router.get('/api/like/list', controller.like.allList);
  router.resources('like', '/api/like', controller.like);

  // 套餐分类
  router.get('/api/category/list', controller.category.allList);
  router.resources('category', '/api/category', controller.category);
  // 套餐
  router.get('/api/goods/list', controller.goods.allList);
  router.resources('goods', '/api/goods', controller.goods);
  // 套餐订单
  router.get('/api/orderGoods/list', controller.orderGoods.allList);
  router.resources('orderGoods', '/api/orderGoods', controller.orderGoods);
  router.resources('orderGoodsDetail', '/api/orderGoodsDetail', controller.orderGoodsDetail);
  router.resources('express', '/api/express', controller.express);

  // 地址
  router.get('/api/address/list', controller.address.allList);
  router.post('/api/address/updateStatus', controller.address.updateStatus);
  router.resources('address', '/api/address', controller.address);
};
